package com.hisysteTopet.hisystepet.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hisysteTopet.hisystepet.bean.ShopCart;
import com.hisysteTopet.hisystepet.bean.UserAndIndent;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.TimerTask;

@Mapper
public interface ShopCartMapper extends BaseMapper<ShopCart> {

    // 添加用户购物车信息
    @Insert("INSERT INTO shop_cart VALUE(#{username},#{petId},#{lifeGoodsId},#{data}," +
            "#{classify},#{url},#{pet_name},#{life_goods_name},#{money})")
    public void InsertShopCartMessage(String username, Integer petId, Integer lifeGoodsId,
                                      Date data,String classify,String url,
                                      String pet_name,String life_goods_name,Double money);

    // 通过ID和用户名查询是否添加了宠物
    @Select("SELECT * FROM shop_cart WHERE username = #{username} AND pet_id = #{PetId}")
    public ShopCart SelectByUsernameAndPetId(String username,Integer PetId);

    // 通过ID和用户名查询是否添加了宠物用品
    @Select("SELECT * FROM shop_cart WHERE username = #{username} AND life_goods_id = #{lifeGoodsId}")
    public ShopCart SelectByUsernameAndLifeGoodsId(String username,Integer lifeGoodsId);

    // 显示宠物购物车的订单信息
    @Select("SELECT * FROM shop_cart WHERE username = #{username}  ORDER BY  shop_cart.`data`  DESC")
    public List<ShopCart> SelectAllShopCartByUsername(String username);

    // 通过Id和分类删除购物车的宠物订单信息
    @Delete("DELETE FROM shop_cart " +
            "WHERE pet_id = #{petId}  AND username = #{username} AND classify = #{classify}")
    public void DeleteshouCartMessageByIdAndClassifyToPet
            (Integer petId,String username,String classify);

    // 通过Id和分类删除购物车的宠物用品订单信息
    @Delete("DELETE FROM shop_cart " +
            "WHERE life_goods_id = #{lifeGoodsId}  AND username = #{username} AND classify = #{classify}")
    public void DeleteshouCartMessageByIdAndClassifyToPetLifeGoods
    (Integer lifeGoodsId,String username,String classify);

}
